package cn.itcalvin.sncoal.cth.pojo.response.analyse;

import cn.itcalvin.sncoal.cth.config.BigDecimalSerialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 卡片下面展示两队矿井数据
 */
@Data
public class RespAnalyseCardItem {
    @ApiModelProperty(value="评分ID,对应的那一次评分")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long pfId;

    @ApiModelProperty(value="矿井ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long mineId;
    @ApiModelProperty(value="矿井名称")
    private String mineName;

    @ApiModelProperty(value="需要对比的总分")
    @JsonSerialize(using = BigDecimalSerialize.class)
    private BigDecimal totalScore;
    @ApiModelProperty(value="实际的分数")
    @JsonSerialize(using = BigDecimalSerialize.class)
    private BigDecimal sjScore;

    /**
     * 获取等级, 颜色区分两种，获取分数>=总分 *0.8  等于1  或者等于2
     *  1.优秀 2.良好 3.一般 4.差 前端用不同颜色区分
     * @return
     */
    public Integer getLevel(){
        if(sjScore==null){
            return 3;
        }
        if(sjScore.setScale(2, RoundingMode.HALF_UP).compareTo(getTotalScore().multiply(new BigDecimal(0.8)).setScale(2, RoundingMode.HALF_UP))>=0){
            return 1;
        }else {
            return 2;
        }
    }
}
